package nii.game.mobileserio.sound;

import java.io.IOException;

import org.anddev.andengine.audio.music.Music;
import org.anddev.andengine.audio.music.MusicFactory;
import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.util.Debug;

import android.content.Context;

public class MusicBg {
	
	private Music mMusic;
	private String filename;
	
	public MusicBg(String _filename){
		filename = _filename;
	}
	//============================|| HÀM LOAD ÂM THANH NỀN CHO GAME||=============================//
	
	public void onLoadResources(Engine mEngine, Context mContext) {
		// Đường dẫn đến thư mục chứa file audio
		MusicFactory.setAssetBasePath("mfx/");
		try{
			mMusic = MusicFactory.createMusicFromAsset(mEngine.getMusicManager(), mContext, filename);
			mMusic.setLooping(true);
		} 
		catch (final IOException e){
			Debug.e(e);
		} 
	}
 
	// Hàm PLAY
	public void Play(){
		mMusic.play(); 		
	}
 
	// Hàm Điều chỉnh âm lượng
	public void SetVolume(float value){
		mMusic.setVolume(value);
	}
	
	// Hàm tắt âm lượng
	public void Mute(){
		mMusic.setVolume(0);
	}
}
